package com.etc.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.etc.entity.Goods;
import com.etc.service.GoodsService;
import com.etc.util.ResponseData;
import com.github.pagehelper.Page;

@RestController
public class GoodsController {

	@Autowired
	private GoodsService service;

	@GetMapping(value = "goods")
	public ResponseData<Goods> listGoods(@RequestParam(value = "page", required = true, defaultValue = "1") int page,
			@RequestParam(value = "limit", required = true, defaultValue = "10") int limit,
			@RequestParam(value = "keywords", required = true, defaultValue = "") String keywords) {

		// 调用service
		Page<Goods> pages = service.getByPage(page, limit, keywords);

		ResponseData<Goods> ar = new ResponseData<Goods>(0, "success", pages.getTotal(), pages.getResult());

		return ar;

	}
}
